package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description: 基于echo server的翻译服务器
 * User:DELL
 * Date:2025-02-26
 * Time:17:38
 */
public class UdpDictServer extends UdpEchoServer {
    private Map<String,String> dict=new HashMap<>();
    public UdpDictServer(int port) throws SocketException {
        super(port);

        //此处可以往表里插入几千几万个这样的英文单词
        dict.put("dog","小狗");
        dict.put("cat","小猫");
        dict.put("pig","小猪");
    }
    //重写process方法，在重写的方法中完成翻译的过程
    //翻译本质上就是查表
    public String process(String request){
        return dict.getOrDefault(request,"该词在词典中不存在！");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer server=new UdpDictServer(9595);
        server.start();
    }
}
